import java.util.TreeSet;

/**
 * @author 司松坡
 * @createTime 2023年02月24日
 */
public class No1906 {
    public int[] minDifference(int[] nums, int[][] queries) {
        int[] ans = new int[queries.length];
        for(int i=0;i<queries.length;i++){
            TreeSet<Integer> set = new TreeSet<Integer>();
            for(int j=queries[i][0];j<=queries[i][1];j++){
                set.add(nums[j]);
            }
            if(set.size() == 1){
                ans[i] = -1;
            }else{
                ans[i] = min(set);
            }
        }
        return ans;
    }

    public int min(TreeSet<Integer> set){
        int a = -100;
        int min = 100;
        for(int i: set){
            min = Math.min(i-a,min);
            a = i;
        }
        return min;
    }
}
